<?php
/**
 * Created By Project
 * Author: 陈东
 * Copyright：陈东
 * Source Code：陈东
 * Explain：I shall not authorize for any other commercial purposes, law breakers must be prosecuted.
 */
namespace Home\Model;
use Think\Model;

class PlateModel extends Model{

    /*=======================历史上的今天=========================*/
    /**
     * 获取历史上的今天列表
     */
    static function history_list_info(){
        $m = ltrim(date("m"), 0);
        $d = ltrim(date("d"), 0);
        $date = $m.'/'.$d;
        $par = array(
            'key'     => C('T_HISTORYAPPKEY'),
            'date'    => $date
        );
        $parstr = parameter_joint_get($par);
        $url = C('T_LIST').$parstr;
        $res = http($url,'GET');
        if($res['error_code'] == 0){
            return $res['result'];
        }else{
            return array('reason' => 'error');
        }
    }

    /**
     * 根据历史列表ID获取详细信息
     */
    static function history_id_info($e_id = null){
        if(empty($e_id)) return null;
        $par = array(
            'key'     => C('T_HISTORYAPPKEY'),
            'e_id'    => $e_id
        );
        $parstr = parameter_joint_get($par);
        $url = C('T_LISTID').$parstr;
        $res = http($url,'GET');
        if($res['error_code'] == 0){
            return $res['result'][0];
        }else{
            return array('reason' => 'error');
        }
    }

    /**
     * 获取历史上的今天的第一条信息
     */
    static function get_history_first_info(){
        $history_list_info = self::history_list_info();
        $history_list_info = self::history_id_info($history_list_info[0]['e_id']);
        return $history_list_info;
    }

    /*=======================微信精选=========================*/
    /**
     * 获取微信精选列表
     */
    static function weixin_list_info(){
        $par = array(
            'ps'      => 50,
            'key'     => C('WEIXIN_APP')
        );
        $parstr = parameter_joint_get($par);
        $url = C('WEIXIN_LIST').$parstr;
        $res = http($url,'POST');
        if($res['error_code'] == 0){
            $r = $res['result']['list'];
            foreach($r as $key => $value){
                if($value['firstImg'] == ''){
                    unset($r[$key]);
                }
            }
            return $r;
        }else{
            return array('reason' => 'error');
        }
    }

    /*=======================新闻头条=========================*/
    /**
     * 获取新闻头条列表
     */
    static function news_list_info(){
        $par = array(
            //type类型 top(头条，默认),shehui(社会),guonei(国内),guoji(国际),yule(娱乐),tiyu(体育)junshi(军事),keji(科技),caijing(财经),shishang(时尚)
            'type'    => 'top',
            'key'     => C('NEWS_APP')
        );
        $parstr = parameter_joint_get($par);
        $url = C('NEWS_LIST').$parstr;
        $res = http($url,'POST');
        if($res['error_code'] == 0){
            return $res['result']['data'];
        }else{
            return array('reason' => 'error');
        }
    }

    /*=======================最新笑话=========================*/
    /**
     * 获取最新笑话列表
     */
    static function xiaohua_list_info(){
        $par = array(
            'pagesize'=> '20',
            'key'     => C('XIAOHUA_APP')
        );
        $parstr = parameter_joint_get($par);
        $url = C('XIAOHUA_LIST').$parstr;
        $res = http($url,'POST');
        if($res['error_code'] == 0){
            return $res['result']['data'];
        }else{
            return array('reason' => 'error');
        }
    }

    /*=======================读取数据库=========================*/
    /**
     * 根据版块ID获取表中内容列表
     */
    static function get_byplateid_content($plateID){
        //$cur_date = date('Y-m-d');
        $pcontent = D(C('TABLE_PLATECONTENT'));
        $res = $pcontent->where("plate_id = {$plateID}")->order('editdate DESC,id DESC')->limit(100)->select();
        return $res;
    }
    /**
     * 历史上的今天
     * 根据e_id获取详细内容
     */
    static function get_eid_content($eid = null){
        $pcontent = D(C('TABLE_PLATECONTENT'));
        $res = $pcontent->where(array('e_id' => $eid))->find();
        return $res;
    }

    /**
     * 根据文章ID获取文章信息
     */
    static function get_article_id_info($id = null){
        $pcontent = D(C('TABLE_PLATECONTENT'));
        $res = $pcontent->find($id);
        return $res;
    }

}